package com.yann.bomb

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import com.yann.bomb.crud.CreateActivity
import com.yann.bomb.crud.DeleteActivity
import com.yann.bomb.crud.FindActivity
import com.yann.bomb.crud.UpdateActivity

class MainActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val btnAdd = findViewById<Button>(R.id.btn_add)
        val btnDel = findViewById<Button>(R.id.btn_delete)
        val btnUpdate = findViewById<Button>(R.id.btn_update)
        val btnFind = findViewById<Button>(R.id.btn_find)

        btnAdd.setOnClickListener(this)
        btnDel.setOnClickListener(this)
        btnUpdate.setOnClickListener(this)
        btnFind.setOnClickListener(this)

    }

    override fun onClick(v: View) {
        val id = v.id
        when (id) {
            R.id.btn_add -> {
                startActivity(Intent(this, CreateActivity::class.java))
            }
            R.id.btn_delete -> {
                val intent = Intent(this, DeleteActivity::class.java)
                startActivity(intent)
            }
            R.id.btn_find -> {
                startActivity(Intent(this, FindActivity::class.java))
            }
            R.id.btn_update -> {
                startActivity(Intent(this, UpdateActivity::class.java))
            }
            else -> {
            }
        }
    }
}

